package com.heima.a07_demo.server.mapper;

import com.heima.a07_demo.pojo.entity.DiagnosisResult;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface DiagnosisResultMapper {
    /*
    * 保存结果
    * */
    @Insert("insert into diagnosis_result (record_id, image_left, image_right, patient_id, doctor_id, " +
            "left_result, right_result, final_result," +
            " disease_left_labels, disease_left_probabilities," +
            " disease_right_labels, disease_right_probabilities, create_time) " +
            "VALUES " +
            "(#{recordId},#{imageLeft},#{imageRight},#{patientId},#{doctorId}," +
            "#{leftResult},#{rightResult},#{finalResult},#{diseaseLeftLabels}," +
            "#{diseaseLeftProbabilities},#{diseaseRightLabels},#{diseaseRightProbabilities},#{createTime})")

    void save(DiagnosisResult diagnosisResult);
    /*
    * 返回报告
    * */
    @Select("SELECT dr.image_left, dr.image_right, dr.disease_left_labels, dr.disease_left_probabilities, " +
            "dr.disease_right_labels, dr.disease_right_probabilities, dr.left_result, dr.right_result, dr.final_result " +
            "FROM diagnosis_result dr " +
            "JOIN diagnosis_record drr ON dr.record_id = drr.record_id " +
            "WHERE drr.patient_id = #{patientId} " +
            "ORDER BY drr.diagnosis_time DESC LIMIT 1")
    DiagnosisResult getLatestDiagnosisResultByPatientId(Long patientId);
}
